home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / nihcl-30.lha / nihcl-3.0 / test / dep.c < prev    next >
C/C++ Source or Header  |  1990-05-19  |  4KB  |  126 lines

  1. /* Test Object dependencies
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Author:
  11.     K. E. Gorlen
  12.     Bg. 12A, Rm. 2033
  13.     Computer Systems Laboratory
  14.     Division of Computer Research and Technology
  15.     National Institutes of Health
  16.     Bethesda, Maryland 20892
  17.     Phone: (301) 496-1111
  18.     uucp: uunet!nih-csl!kgorlen
  19.     Internet:kgorlen@alw.nih.gov
  20.  
  21. Function:
  22.     
  23. Modification History:
  24.     
  25. $Log:    dep.c,v $
  26.  * Revision 3.0  90/05/20  00:28:58  kgorlen
  27.  * Release for 1st edition.
  28.  * 
  29. */
  30. static char rcsid[] = "$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/test/RCS/dep.c,v 3.0 90/05/20 00:28:58 kgorlen Rel $";
  31.  
  32. #include "Point.h"
  33. #include "OrderedCltn.h"
  34.  
  35. class MyPoint: public Point {
  36.     DECLARE_MEMBERS(MyPoint);
  37. public:
  38.     MyPoint(int newx, int newy) : Point(newx,newy) {}
  39.     ~MyPoint()    { release(); }
  40.     int x() const    { return Point::xc; }
  41.     int y() const    { return Point::yc; }
  42.     int x(int newx)    { Point::xc = newx; changed(); return Point::xc; }
  43.     int y(int newy)    { Point::yc = newy; changed(); return Point::yc; }
  44. #ifndef BUG_38
  45. // internal <<AT&T C++ Translator 2.00 06/30/89>> error: bus error (or something nasty like that)
  46. protected:        // storer() functions for object I/O
  47.     virtual    void storer(OIOofd& fd)    const    { Point::storer(fd); }
  48.     virtual    void storer(OIOout& strm) const    { Point::storer(strm); }
  49. #endif
  50. };
  51.  
  52. MyPoint::MyPoint(OIOin&) {}
  53.  
  54. MyPoint::MyPoint(OIOifd&) {}
  55.  
  56. #define BASE Point
  57. #define BASE_CLASSES Point::desc()
  58. #define MEMBER_CLASSES
  59. #define VIRTUAL_BASE_CLASSES
  60.  
  61. DEFINE_CLASS(MyPoint,1,"$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/test/RCS/dep.c,v 3.0 90/05/20 00:28:58 kgorlen Rel $",NULL,NULL);
  62.  
  63. class PointView: public VIRTUAL Object {
  64.     DECLARE_MEMBERS(PointView);
  65.     Point* p;
  66. public:
  67.     PointView(Point& newp)    { p = &newp; p->addDependent(*this); update(*p,*nil); }
  68.     ~PointView()        { p->removeDependent(*this); }
  69.     virtual int compare(const Object&) const;
  70.     virtual void deepenShallowCopy();
  71.     virtual unsigned hash() const;
  72.     virtual bool isEqual(const Object&) const;
  73.     virtual void update(const Object&, const Object&);
  74.     virtual void printOn(ostream& strm =cout) const;
  75. };
  76.  
  77. #undef BASE
  78. #define BASE Object
  79. #undef BASE_CLASSES
  80. #define BASE_CLASSES Object::desc()
  81.  
  82. DEFINE_CLASS(PointView,1,"$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/test/RCS/dep.c,v 3.0 90/05/20 00:28:58 kgorlen Rel $",NULL,NULL);
  83.  
  84. int PointView::compare(const Object& a) const { return p->compare(a); }
  85.  
  86. void PointView::deepenShallowCopy()
  87. {
  88.     p = Point::castdown(p->deepCopy());
  89. }
  90.  
  91. unsigned PointView::hash() const    { return p->hash(); }
  92.  
  93. bool PointView::isEqual(const Object& a) const    { return p->isEqual(a); }
  94.  
  95. void PointView::update(const Object& p, const Object& /*unused*/)
  96. {
  97.     cout << p.className() << " changed: " << p << endl;
  98.     cout.flush();
  99. }
  100.  
  101. void PointView::printOn(ostream& strm) const
  102. {
  103.     strm << *p << endl;
  104. }
  105.  
  106. PointView::PointView(OIOin&) {}
  107.  
  108. PointView::PointView(OIOifd&) {}
  109.  
  110. main()
  111. {
  112.     cout << "Test Object Dependencies" << endl;
  113.     MyPoint p(0,0);
  114.     PointView* v = new PointView(p);
  115.     p.dependents().dumpOn(cout);
  116.     p.x(1); p.y(2);        /* should print changes */
  117.     delete v;
  118.     p.dependents().dumpOn(cout);
  119.     p.x(3); p.y(4);        /* should not print changes */
  120.     v = new PointView(p);
  121.     p.x(5); p.y(6);        /* should print changes */
  122.     p.release();
  123.     p.dependents().dumpOn(cout);
  124.     p.x(7); p.y(8);        /* should not print changes */
  125. }
  126.